package com.supermap.application.dao;

import com.supermap.application.entity.TMacroData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface MacroDataDao extends JpaRepository<TMacroData,String> {

    @Override
    List<TMacroData> findAll();

    @Query("select t.d00001 from TMacroData t where t.year = :year and t.reportTime = '12' and t.dataType = '1'")
    String computeGDP(@Param("year") String year);

    @Query("select t.g00001 from TMacroData t where t.year = :year and t.reportTime = '12' and t.dataType = '1'")
    String computeFixedAssets(@Param("year") String year);

    @Query("select t.x00004 from TMacroData t where t.year = :year and t.reportTime = '12' and t.dataType = '1'")
    String computeSell(@Param("year") String year);

    @Query("select t.j00002 from TMacroData t where t.year = :year and t.reportTime = '12' and t.dataType = '1'")
    String computeExit(@Param("year") String year);

    //计算最小报告期和最大报告期
    @Query("select min(cast (t.reportTime as int)),max(cast (t.reportTime as int)) from TMacroData t where t.year = :year and t.dataType = '1'")
    List computeExtremeReport(@Param("year") String year);

    //规模以上工业时间值数据
    @Query("select t.r00004,t.year,t.reportTime from TMacroData t where t.year = :year and t.dataType = '1'")
    List getAboveIndustry(@Param("year") String year);


    //房地产开发额时间值数据
    @Query("select t.g00003,t.year,t.reportTime from TMacroData t where t.year = :year and t.dataType = '1'")
    List getRealty(@Param("year") String year);

    //常住人口时间值数据
    @Query("select t.c00003,t.year,t.reportTime from TMacroData t where t.year = :year and t.dataType = '1'")
    List getRatepay(@Param("year") String year);

    //宏观数据
    @Query("select t from TMacroData t where t.year = :year and t.dataType = '1'")
    List<TMacroData> getMacroDataList(@Param("year") String year);


    //年末常住人口数据
    @Query("select t.z00003,t.year,t.reportTime from TMacroData t where  t.dataType = '1' and t.reportTime = '12'")
    List getPopulation();


    @Query("select t from TMacroData t where t.dataType = '2'")
    TMacroData getAllUnit();
}
